#include "Echart.h"
#include "echart_private.h"
/*============================================================================*
 *                                  Local                                     *
 *============================================================================*/
static int _init = 0;
/*============================================================================*
 *                                 Global                                     *
 *============================================================================*/
void echart_new(Echart *ec, Echart_Type type)
{
	ec->type = type;
	ec->width = 320;
	ec->height = 240;
}
/*============================================================================*
 *                                   API                                      *
 *============================================================================*/
/**
 * To be documented
 * FIXME: To be fixed
 */
EAPI void echart_init(void)
{
	if (!_init++)
		eina_init();
}
/**
 * To be documented
 * FIXME: To be fixed
 */
EAPI void echart_shutdown(void)
{
	if (!--_init)
		eina_shutdown();
}
/**
 * To be documented
 * FIXME: To be fixed
 */
EAPI void echart_free(Echart *ec)
{
	/* call the implementation */
	if (ec->title)
		free(ec->title);
	free(ec);
}
/**
 * To be documented
 * FIXME: To be fixed
 */

EAPI void echart_title_set(Echart *ec, const char *title)
{
	ec->title = strdup(title);
}
/**
 * To be documented
 * FIXME: To be fixed
 */

EAPI char * echart_title_get(Echart *ec)
{
	return ec->title;
}
/**
 * To be documented
 * FIXME: To be fixed
 */

EAPI void echart_width_set(Echart *ec, unsigned int width)
{
	ec->width = width;
}
/**
 * To be documented
 * FIXME: To be fixed
 */

EAPI void echart_height_set(Echart *ec, unsigned int height)
{
	ec->height = height;
}
/**
 * To be documented
 * FIXME: To be fixed
 */

EAPI void echart_size_get(Echart *ec, unsigned int *width, unsigned int *height)
{
	if (width) *width = ec->width;
	if (height) *height = ec->height;
}
/**
 * To be documented
 * FIXME: To be fixed
 */

EAPI void echart_title_color_set(Echart *ec, Echart_Color color)
{
	ec->color = color;
}
/**
 * To be documented
 * FIXME: To be fixed
 */

EAPI Echart_Color echart_title_color_get(Echart *ec)
{
	return ec->color;
}
/**
 * To be documented
 * FIXME: To be fixed
 */

EAPI Echart_Type echart_type_get(Echart *ec)
{
	return ec->type;
}
/**
 * To be documented
 * FIXME: To be fixed
 */

EAPI void echart_generate(Echart *ec, Echart_Backend *backend, void *data)
{
	if (!backend) return;
	if (!backend->generate) return;

	backend->generate(ec, data);
}
/**
 * To be documented
 * FIXME: To be fixed
 */

EAPI Echart_Dataset * echart_dataset_get(Echart *ec)
{
	return EINA_INLIST_CONTAINER_GET(ec->datasets, Echart_Dataset);
}
/**
 * To be documented
 * FIXME: To be fixed
 */

EAPI void echart_dataset_add(Echart *ec, Echart_Dataset *ds)
{
	ec->datasets = eina_inlist_append(ec->datasets, EINA_INLIST_GET(ds));
}

/**
 * To be documented
 * FIXME: To be fixed
 */
EAPI void echart_dataset_remove(Echart *ec, Echart_Dataset *ds)
{
	ec->datasets = eina_inlist_remove(ec->datasets, EINA_INLIST_GET(ds));
}

